Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expectDocCommentIncludes assertion #155

Merged
merged 12 commits into from
Sep 14, 2022

Conversation

tommy-mitchell
Copy link
Contributor

Adds an assertion to check the documentation comment of a given expression:

/** FooBar */
const foo = 'bar';

expectDocComment<'FooBar'>(foo);

Fails if the type parameter does not exist, is not a string literal, or does not match the given expression's doc comment.

In one project, I have a function that takes a set of user-defined extension functions and maps them onto the built-ins. expectDocComment can help ensure that the type hinting for the user-defined extensions are mapped correctly.

@sindresorhus
Copy link
Collaborator

It doesn't really make sense to me that it's matching the whole doc comment. That would make the assertion huge. I think something like expectDocumentationCommentToContain() would be more practical. So you can assert that the doc comment contains a certain substring.

@tommy-mitchell
Copy link
Contributor Author

I agree, I wanted to see what your thoughts were before making the match non-exact. I went with expectDocCommentIncludes since it's less verbose and matches string.includes().

@tommy-mitchell tommy-mitchell changed the title Add expectDocComment assertion Add expectDocCommentIncludes assertion Sep 11, 2022
@sindresorhus
Copy link
Collaborator

Can you fix the merge conflict?

@tommy-mitchell
Copy link
Contributor Author

Merged.

@sindresorhus sindresorhus merged commit c3d0949 into tsdjs:main Sep 14, 2022
tommy-mitchell added a commit to tommy-mitchell/tsd that referenced this pull request Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants